package org.android.cosmus.indiam.utilities;

import org.android.cosmus.indiam.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.widget.TextView;
import android.widget.Toast;

public class Utils
{

  public static void makeAlertDialog(Activity context, String title, String text)
  {
    TextView listInformation = (TextView) context.getLayoutInflater().inflate(R.layout.list_text_information, null);
    listInformation.setText(text);
    new AlertDialog.Builder(context).setTitle(title)
                                    .setView(listInformation)
                                    .setPositiveButton(R.string.ok, null)
                                    .show();
  }
  
  public static void makeToast(Context context, String text)
  {
    Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
    toast.show();  
  }
  
  public static int getResourceDrawableIdBasedOnName(Context context, String resourceName, String sufix)
  {
    return getResourceIdBasedOnName(context, resourceName, "drawable", sufix);
  }
  
  public static int getResourceArrayIdBasedOnName(Context context, String resourceName, String sufix)
  {
    return getResourceIdBasedOnName(context, resourceName, "array", sufix);
  }
  
  public static int getResourceStringIdBasedOnName(Context context, String resourceName, String sufix)
  {
    return getResourceIdBasedOnName(context, resourceName, "string", sufix);
  }
  
  private static int getResourceIdBasedOnName(Context context, String resourceName, String resourceType, String sufix)
  {
    String filteredResourceName = resourceName.toLowerCase().trim().replace(" ", "_").replace(",", "").replace("-", "_");
    return context.getResources().getIdentifier(filteredResourceName + sufix, resourceType, context.getString(R.string.package_str));
  }
  
}
